package mn.more.wits.client.dto;

/**
 * @author <a href="mailto:mike.liu@aptechmongolia.edu.mn">Mike Liu</a>
 * @version $Revision: 119 $
 */
public class ExamListDTO extends DataTransferObject {

	private ExamSummaryDTO[] summaries;

	protected void beforeSerialize() {
		if (summaries != null) {
			StringBuffer buffer = new StringBuffer();
			for (int i = 0; i < summaries.length; i++) {
				buffer.append(toModelString(summaries[i])).append(ARRAY_DELIM);
			}
			setData("summaries", buffer.toString());
		}
	}

	protected void afterDeserialize() {
		String data = getData("summaries");
		if (data != null) {
			String[] summariesString = data.split(ARRAY_DELIM_STR);
			ExamSummaryDTO[] summaries = new ExamSummaryDTO[summariesString.length];
			for (int i = 0; i < summariesString.length; i++) {
				summaries[i] = (ExamSummaryDTO) toBaseModel(summariesString[i], new ExamSummaryDTO());
			}

			this.summaries = summaries;
		}
	}

	public ExamSummaryDTO[] getSummaries() { return summaries; }

	public void setSummaries(ExamSummaryDTO[] summaries) { this.summaries = summaries; }

	//public boolean add(Object o) {
	//	if (!(o instanceof ExamSummaryDTO)) { throw new ClassCastException("Unexpected type: " + o); }
	//	return super.add(o);
	//}
	//
	//public void add(int index, Object o) {
	//	if (!(o instanceof ExamSummaryDTO)) { throw new ClassCastException("Unexpected type: " + o); }
	//	super.add(index, o);
	//}
	//
	//public Object get(int index) {
	//	return super.get(index);
	//}
	//
	//public Object set(int index, Object o) {
	//	if (!(o instanceof ExamSummaryDTO)) { throw new ClassCastException("Unexpected type: " + o); }
	//	return super.set(index, o);
	//}
	//
	//public ExamSummaryDTO addNewSummary() {
	//	ExamSummaryDTO s = new ExamSummaryDTO();
	//	// default
	//	s.setTeamwork(false);
	//	add(s);
	//	return s;
	//}
}
